<!-- 首页 -->
<template>
	<view class="index-body">
		<pNavbar></pNavbar>
		<!-- 调查 -->
		<investigate v-show="tabbarValue === 0"></investigate>
		<!-- 采样 -->
		<sampling v-show="tabbarValue === 1"></sampling>
		<!-- 监测井 -->
		<!-- 更多 -->
		<!-- 		<view class="top-tabs">
			<pTabs @tabsClick="tabsClick"></pTabs>
			<u-divider></u-divider>
			<view class="tabs-input-con">
				<indexSearchInput></indexSearchInput>
			</view>
		</view> -->
		<!-- 		<scroll-view scroll-y class="content">
			<u-cell-group>
				<u-cell v-for="(item) in itemIndex" :key="item" :isLink="true" size="large" :title="'xxx水源' + item"
					label="昆明市五华区地下水型饮用水源" @click="clickCell">
					<text slot="value" class="tag-text-red">退回</text>
				</u-cell>
			</u-cell-group>
		</scroll-view> -->
		<!-- 		<view style="padding: 20px;">
			<u-button type="primary" text="login" @click="gotoLogin"></u-button>
		</view>
		<view style="padding: 20px;">
			<u-button type="primary" :plain="true" text="拍照" @click="paizhao"></u-button>
		</view>
		<view style="padding: 20px;">
			<u-button type="primary" :plain="true" text="扫码" @click="saoma"></u-button>
		</view> -->
		<!-- <bluetooth /> -->
		<!-- <xunBluetoothPrint /> -->
		<pTabbar @valueChange="valueChange"></pTabbar>
	</view>
</template>

<script>
	import bluetooth from '@/components/bluetooth.vue';
	import xunBluetoothPrint from '@/components/xun-bluetoothPrint/index.vue';
	import indexSearchInput from '../components/indexSearchInput.vue';
	import investigate from '../investigate/investigate.vue';
	import sampling from '../sampling/sampling.vue';
	import pageMixins from '@/mixins/pageMixins.js';
	export default {
		mixins: [pageMixins],
		components: {
			bluetooth,
			xunBluetoothPrint,
			indexSearchInput,
			investigate,
			sampling,
		},
		data() {
			return {
				disabled: true,
				deviceId: '', // 蓝牙设备ID
				serviceId: '', // 蓝牙服务ID
				characteristicId: '', // 蓝牙特征值ID,
				itemIndex: 5,
				tabbarValue: 0,

			}
		},
		/**
		 * 下拉刷新事件
		 */
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			valueChange(e) {
				this.tabbarValue = e;
			},
			paizhao() {
				console.log('拍照');
				uni.chooseImage({
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths));
					}
				});
			},
			saoma() {
				console.log('扫码');
				// 允许从相机和相册扫码
				uni.scanCode({
					scanType: ['barCode'], // 调起条码扫描
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			},
			connectBluetooth() {
				// 连接蓝牙设备
				uni.createBLEConnection({
					deviceId: this.deviceId,
					success: (res) => {
						console.log('蓝牙设备连接成功', res);
						// 连接成功后进行文件传输
						this.sendFileData();
					},
					fail: (err) => {
						console.error('蓝牙设备连接失败', err);
					}
				});
			},
			sendFileData() {
				// 向蓝牙设备写入文件数据
				uni.writeBLECharacteristicValue({
					deviceId: this.deviceId,
					serviceId: this.serviceId,
					characteristicId: this.characteristicId,
					value: '你要传输的文件数据',
					success: (res) => {
						console.log('文件数据写入成功', res);
						// 文件数据写入成功后的逻辑处理
					},
					fail: (err) => {
						console.error('文件数据写入失败', err);
					}
				});
			}
		},
	}
</script>

<style lang="scss" scoped>
	.index-body {
		max-height: 100vh;
		overflow: hidden;
		padding-bottom: 100rpx;
	}
</style>